package com.jlwl.houseservice.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jlwl.houseservice.common.Result;
import com.jlwl.houseservice.entity.Feedback;
import com.jlwl.houseservice.service.FeedbackService;
import com.jlwl.houseservice.vo.FeedbackQueryVO;
import com.jlwl.houseservice.vo.FeedbackReplyVO;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员反馈控制器
 */
@RestController
@RequestMapping("/admin/feedback")
@PreAuthorize("hasRole('ADMIN')")
public class AdminFeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    /**
     * 获取反馈列表
     */
    @GetMapping
    public Result<Page<Feedback>> list(FeedbackQueryVO queryVO) {
        Page<Feedback> page = feedbackService.pageList(queryVO);
        return Result.success(page);
    }

    /**
     * 回复反馈
     */
    @PutMapping("/{id}/reply")
    public Result<Void> reply(@PathVariable Integer id, @Valid @RequestBody FeedbackReplyVO replyVO) {
        boolean success = feedbackService.replyFeedback(id, replyVO);
        if (!success) {
            return Result.error("回复反馈失败");
        }
        return Result.success();
    }

    /**
     * 更新反馈状态
     */
    @PutMapping("/{id}/status")
    public Result<Void> updateStatus(@PathVariable Integer id, @RequestParam Integer status) {
        boolean success = feedbackService.updateFeedbackStatus(id, status);
        if (!success) {
            return Result.error("更新反馈状态失败");
        }
        return Result.success();
    }
} 